<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>蓝源Eloan-P2P平台->用户注册</title>
<link rel="stylesheet" href="/js/bootstrap-3.3.2-dist/css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="/css/core.css" type="text/css" />
<script type="text/javascript" src="/js/jquery/jquery-2.1.3.js"></script>
<script type="text/javascript" src="/js/bootstrap-3.3.2-dist/js/bootstrap.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-validation/jquery.validate.min.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-validation/messages_cn.js"></script>
<script type="text/javascript" src="/js/plugins/jquery.form.js"></script>
<script type="text/javascript" src="/js/jquery.bootstrap.min.js"></script>

<style type="text/css">
	.el-register-form{
		width:600px; 
		margin-left:auto;
		margin-right:auto;
		margin-top: 20px;
	}
	.el-register-form .form-control{
		width: 220px;
		display: inline;
	}
	input[name='verifycode'] + label{
		position: absolute;
		top: 7px;
		left:220px;
	}
</style>
<script type="text/javascript">

	//手机号码正则表达式验证
    function checkPhone(phone){
        if(!(/^1[345789]\d{9}$/.test(phone))){
            return false;
        }
        return true;
	}
	$(function(){
	    //发送验证码
		$('#sendVerifyCode').click(function () {
			//判断手机号格式
			var phone = $('#phoneNumber').val();
			if(checkPhone(phone)){
			    //按钮禁用
				var btn = $(this);
				btn.attr('disabled', true);
				//执行发送
				$.post('/sendVerifyCode',{"phone": phone}, function (data) {
					//发送成功
					if(data.success){
					    $.messager.alert("提示","验证码已发送到您的手机,请在5分钟内使用")
						//按钮倒计时
						var time = 60;
						var interval = window.setInterval(function () {
							btn.html(time + "s后重新发送")
							time--;
							//清除计时器
							if(time <= 0){
								window.clearInterval(interval);
								//启用按钮
								btn.attr("disabled", false);
								btn.html("重新发送");
							}
						},1000);
					}else{
					    //发送失败
						$.messager.alert("提示", data.message);
                        btn.attr("disabled", false);
                        btn.html("重新发送");
					}

                });
			}else{
                $.messager.alert("提示", "手机号格式不正确");
			}
        });
	    //手机号码格式的验证
        jQuery.validator.addMethod("isPhone", function(phone, element) {
            return checkPhone(phone);
        }, "无效的手机号码");

        $("#registerForm").validate({
			//错误提示的样式,使用bootstrap情景样式替换默认的error样式,即由黑变红
			errorClass:"text-danger",
			//highlight:表单中某个元素验证不通过就触发该函数
			highlight: function (element, errorClass) {
                $(element).fadeOut(function() {
                    $(element).fadeIn();
                });
                $(element).closest('div .form-group').addClass('has-error').removeClass('has-success');
            },
			//unhighlight:表单中某个元素验证通过的时候调用该回调函数
            unhighlight: function (element, errorClass) {
                $(element).closest('div .form-group').removeClass('has-error').addClass('has-success');
			},
			//submitHandler 表单验证通过之后触发该函数,并且会阻止表单的默认提交
            submitHandler:function(form){
                $(form).ajaxSubmit(function (data) {
					if(data.success){
					    $.messager.confirm('提示','注册成功', function () {
							window.location.href='/login.html';
                        });
					}else{
                        $.messager.alert('提示',data.message);
					}
                });
            },
            rules: {
                username: {
                    required: true,
                    rangelength: [11,11],
					number: true,
					"isPhone": "isPhone",
					remote: "/existUsername"
				},
                verifycode: {
                    required: true,
                    rangelength: [4,4]
                },
                password: {
                    required: true,
                    rangelength: [6,16]
                },
                confirmPwd: {
                    required: true,
                    rangelength: [6,16],
                    equalTo: "#password"
                }
            },
            messages: {
                username: {
                    required: "请输入手机号,不能为空",
                    rangelength: "请输入{0}位手机号码",
					remote: "手机号已被注册"
                },
                verifycode: {
                    required:  "请输入验证码,不能为空",
                    rangelength: "验证码长度为{0}位"
                },
                password: {
                    required: "请输入密码,不能为空",
                    rangelength: "密码长度为{0}-{1}个字母,数字,下划线组成"
                },
                confirmPwd: {
                    required: "请确认输入密码",
                    rangelength: "密码长度为{0}-{1}个字母,数字,下划线组成",
                    equalTo: "两次密码输入不一致"
                }
            }
        })

	})
</script>
</head>
<body>
	<!-- 网页头信息 -->
	<div class="el-header" >
		<div class="container" style="position: relative;">
			<ul class="nav navbar-nav navbar-right">
				<li><a href="/">首页</a></li>
				<li><a href="/login.html">登录</a></li>
				<li><a href="#">帮助</a></li>
			</ul>
		</div>
	</div>
	
	<!-- 网页导航 --> 
	<div class="navbar navbar-default el-navbar">
		<div class="container">
			<div class="navbar-header">
				<a href=""><img alt="Brand" src="/images/logo.png"></a>
				<span class="el-page-title">用户注册</span>
			</div>
		</div>
	</div>
	
	<!-- 网页内容 -->
	<div class="container">  
		<form id="registerForm" class="form-horizontal el-register-form"  action="/userRegister" method="post" >
			<p class="h4" style="margin: 10px 10px 20px;color:#999;">请填写注册信息，点击“提交注册”即可完成注册！</p>
			<!--<div class="form-group">-->
				<!--<label class="control-label col-sm-2">用户名</label>-->
				<!--<div class="col-sm-10">-->
					<!--<input type="text" placeholder="用户名" autocomplete="off" name="username" class="form-control" id="username"/>-->
					<!--<p class="help-block">用户名为4~16位字母，数字，符号或中文</p>-->
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">
				<label class="control-label col-sm-2">手机号码</label>
				<div class="col-sm-10">
					<input type="text" placeholder="手机号码" autocomplete="off" name="username" class="form-control" id="phoneNumber" value="13112345123"/>
					<p class="help-block">请使用输入正确的手机号码</p>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">手机验证码</label>
				<div class="col-sm-10">
					<input type="text" placeholder="手机验证码" style="width: 100px" autocomplete="off" name="verifycode" class="form-control" id="verifycode"/>
					<button type="button" class="btn btn-success" id="sendVerifyCode">
						发送验证码
					</button>
					<p class="help-block">请输入4位验证码</p>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">密&emsp;码</label>
				<div class="col-sm-10">
					<input type="password" placeholder="密码" autocomplete="off" name="password" id="password" class="form-control" value="000000"/>
					<p class="help-block">密码为6~16位字符组成,采用数字、字母、符号安全性更高</p>
				</div> 
			</div>
			<div class="form-group">
				<label class="control-label col-sm-2">确认密码</label>
				<div class="col-sm-10">
					<input type="password" autocomplete="off" name="confirmPwd" class="form-control" value="000000" />
					<p class="help-block">请再次填写密码</p>	 
				</div>
			</div> 
			<div class="form-gorup">   
				<div class="col-sm-offset-2">  
					<button type="submit" class="btn btn-success">
						同意协议并注册
					</button>
					&emsp;&emsp;
					<a href="/login.html" class="text-primary">已有账号，马上登录</a>
					
					<p style="padding-left: 50px;margin-top: 15px;">
						<a href="#">《使用协议说明书》</a>
					</p>
				</div>
			</div>
		</form>
	</div>
	<!-- 网页版权 -->
	<div class="container-foot-2">
		<div class="context">
			<div class="left">
				<p>专注于高级Java开发工程师的培养</p>
				<p>版权所有：&emsp;2015广州小码哥教育科技有限公司</p>
				<p>地&emsp;&emsp;址：&emsp;广州市天河区棠下荷光三横路盛达商务园D座5楼</p>
				<p>电&emsp;&emsp;话： 020-29007520&emsp;&emsp;
					邮箱：&emsp;service@520it.com</p>
				<p>
					<a href="http://www.miitbeian.gov.cn" style="color: #ffffff">ICP备案
						：粤ICP备字1504547</a>
				</p>
				<p>
					<a href="http://www.gzjd.gov.cn/wlaqjc/open/validateSite.do" style="color: #ffffff">穗公网安备：44010650010086</a>
				</p>
			</div>
			<div class="right">
				<a target="_blank" href="http://weibo.com/ITxiaomage"><img
					src="/images/sina.png"></a>
			</div>
			<div class="clearfix"></div>
		</div>
	</div>
</body>
</html>